// 导入数据库模型
const { GoodsModel, CartModel } = require('../db/model')

// 添加购物车
const addCart = async (req ,res) => {
  const { goodsId } = req.body
  const userId = req.userId
  const goods = await GoodsModel.findOne({ _id: goodsId })
  const result = await CartModel({
    user_id: userId,
    goods_id: goods._id,
    goods_title: goods.title,
    goods_img: goods.img,
    goods_link: goods.link,
    goods_price: goods.price,
    total_price: goods.price
  }).save()

  res.send({
    code: 1,
    message: '添加购物车成功'
  })
}



module.exports = {
  addCart,
}
